/*
 * Copyright 2002-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package gao.test.tomcat.servletcontainerInitializer;

import java.lang.reflect.Modifier;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.HandlesTypes;

import org.springframework.web.WebApplicationInitializer;


@HandlesTypes(WebApplicationInitializer.class)
public class MyServletContainerInitializer implements ServletContainerInitializer {

	
	@Override
	public void onStartup( Set<Class<?>> webAppInitializerClasses, ServletContext servletContext)
			throws ServletException {

		List<WebApplicationInitializer> initializers = new LinkedList<>();

		if (webAppInitializerClasses != null) {
			for (Class<?> waiClass : webAppInitializerClasses) {
				// Be defensive: Some servlet containers provide us with invalid classes,
				// no matter what @HandlesTypes says...
				if (!waiClass.isInterface() && !Modifier.isAbstract(waiClass.getModifiers()) &&
						WebApplicationInitializer.class.isAssignableFrom(waiClass)) {
					/*
					 * try { initializers.add((WebApplicationInitializer)
					 * ReflectionUtils.accessibleConstructor(waiClass).newInstance()); } catch
					 * (Throwable ex) { throw new
					 * ServletException("Failed to instantiate WebApplicationInitializer class",
					 * ex); }
					 */
					
					System.out.println("---------------------------"+waiClass.getName()+"--------------------------");
				}else {
					System.out.println("------------******---------------"+waiClass.getName()+"-----------------****---------");
				}
			}
		}

		/*
		 * if (initializers.isEmpty()) { servletContext.
		 * log("No Spring WebApplicationInitializer types detected on classpath");
		 * return; }
		 * 
		 * servletContext.log(initializers.size() +
		 * " Spring WebApplicationInitializers detected on classpath");
		 * AnnotationAwareOrderComparator.sort(initializers); for
		 * (WebApplicationInitializer initializer : initializers) {
		 * initializer.onStartup(servletContext); }
		 */
	}

}
